package org.example.file;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
import java.util.Collections;

public class FileCreateAndWrite {
    public static final String NEW_LINE = System.lineSeparator();
    public static final String path = "C:\\Users\\JohnConnor\\Documents\\Downloads\\aaa.txt";
    public static void main(String[] args) throws IOException {



    }

    static void test1() throws IOException {
        Files.write(Paths.get(path),("Hello World 1" + NEW_LINE).getBytes(StandardCharsets.UTF_8),
                StandardOpenOption.CREATE,StandardOpenOption.APPEND);
        System.err.println(String.join("", Collections.nCopies(50, "-")));
        Files.write(Paths.get(path), Arrays.asList("a","b","c"),StandardOpenOption.CREATE,
                StandardOpenOption.APPEND);
    }

    static void test2() throws IOException {
        String content = "HelloWorld" + NEW_LINE;
        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path))) {
            bufferedWriter.write(content);
            bufferedWriter.newLine();
        }
    }
}
